import { ApiProperty } from '@nestjs/swagger';

export class ResponseDataProps<T = any> {
  @ApiProperty({ description: '返回状态码' })
  code: number;

  @ApiProperty({ description: '返回信息' })
  message: string;

  @ApiProperty({ description: '返回数据' })
  data?: T;

  [key: string]: any;
}

export class ResponseData {
  private static status_success: number = 0;
  private static status_error: number = -1;

  static success(data: any = {}, message?: string): ResponseDataProps {
    return {
      code: this.status_success,
      message: message || 'success',
      // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
      data,
    };
  }
  static error(message?: string): ResponseDataProps {
    return {
      code: this.status_error,
      message: message || 'failed',
    };
  }
}
